package com.zretc.personcentre.controller;


import com.fasterxml.jackson.databind.ObjectMapper;
import com.zretc.api.pojo.UserInfo;
import com.zretc.api.pojo.blog;
import com.zretc.api.pojo.personcentreModule.Points;
import com.zretc.api.pojo.recommendModule.Applications;
import com.zretc.api.pojo.recommendModule.Recommend;
import com.zretc.common.entity.R;
import com.zretc.common.entity.RespResult;
import com.zretc.personcentre.service.PersonCentreService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;


@RestController
@RequestMapping("/personcentre")
public class PersonCentreController {
    @Autowired
    private PersonCentreService personCentreService;

    @GetMapping("/showPersonMessage")
    public RespResult<UserInfo> ShowPersonMessage(){
        return personCentreService.ShowPersonMessage();
}
    @PutMapping("/updatePersonMessage")
    public RespResult<String> UpdatePersonMessage(@RequestParam("dto") String userInfostr,
                                                  @RequestParam("file") MultipartFile file) throws Exception {
        UserInfo userInfo =  new ObjectMapper().readValue(userInfostr, UserInfo.class);
        return   personCentreService.UpdatePersonMessage(userInfo,file);
    }
    @GetMapping("/showParticipateActivity")
    public RespResult ShowParticipateActivity(Integer pageNum, Integer pageSize){
        return R.success(personCentreService.ShowParticipateActivity(pageNum,pageSize)) ;
    }
    @GetMapping("/showPublishedBlog")
    public RespResult<blog> ShowPublishedBlog(Integer pageNum, Integer pageSize){
        return R.success(personCentreService.ShowPublishedBlog(pageNum,pageSize));
    }
    @GetMapping("/showApplidRecommend")
    public RespResult<Applications> ShowApplidRecommend(Integer pageNum, Integer pageSize){
        return R.success(personCentreService.ShowApplidRecommend(pageNum,pageSize));

    }
    @PostMapping("/uploadjianli")
    public RespResult uploadfile(@RequestParam("file") MultipartFile file) throws Exception {
        return personCentreService.upload(file);
    }
    @GetMapping("/showRecommend")
    public RespResult<Recommend> ShowRecommend(Integer pageNum, Integer pageSize){
        return R.success(personCentreService.ShowRecommend(pageNum,pageSize));

    }
    @PutMapping("/deleteRecommend/{id}")
    public RespResult<String> DeleteRecommend(@PathVariable("id")Integer id){
        return personCentreService.DeleteRecommend(id) ;
    }

    @GetMapping("/showPoints")
    public RespResult<Points> ShowPoints(Integer pageNum, Integer pageSize){
        return R.success(personCentreService.ShowPoints(pageNum,pageSize));
    }
    @GetMapping("/downloadjianli")
    public RespResult downloadfile(){
        return personCentreService.download();
    }
    @GetMapping("/downloadApplication")
    public RespResult downloadApplication(Integer applicationId){
        return personCentreService.downloadApplication(applicationId);
    }

}
